// 基础路径 注意发布之前要先修改这里
let baseUrl = '/'
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}
const website = require(resolve('src/config/website.js'))
module.exports = {
  publicPath: baseUrl, // 根据你的实际情况更改这里
  lintOnSave: true,
  productionSourceMap: false,
  devServer: {
    proxy: (() => {
      if (website.devServer != '/') {
        return {
          '/': {
            target: website.devServer,
            changeOrigin: true,
          }
        }
      }
      return null
    })(),
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: '后台管理系统',
    resolve: {
      alias: {
        '@': resolve('src'),
        'components': resolve('src/components'),
        'api': resolve('src/api'),
        'store': resolve('src/store'),
      }
    },
    plugins: (() => {
      if (process.env.NODE_ENV === 'production') {
        //打包时查看包大小
        return [new BundleAnalyzerPlugin()]
      }
      return []
    })()
  },
  chainWebpack: (config) => {
    //忽略的打包文件
    config.externals({
      'vue': 'Vue',
      'vue-router': 'VueRouter',
      'vuex': 'Vuex',
      'axios': 'axios',
      'element-ui': 'ELEMENT',
    })
    const entry = config.entry('app')
    entry
      .add('babel-polyfill')
      .end()
    entry
      .add('classlist-polyfill')
      .end()
    entry
      .add('@/mock')
      .end()
  }
}